class Solution {
    public int maxProfit(int[] prices) {
        int maxprofit = 0;
        int minprice = Integer.MAX_VALUE;
        for (int i = 0; i < prices.length; i++) {
            minprice = Math.min(prices[i],minprice);
            maxprofit = Math.max(maxprofit,prices[i] - minprice);
            //if (prices[i] < minprice) minprice = prices[i];
            //else if (prices[i] - minprice > maxprofit) maxprofit = prices[i] - minprice;
        }
        return maxprofit;
    }
}